(function($){
	//翻页页码组件
	//pageCount：一页显示数，默认10
	//callBack：查询的回调方法
	$.fn.turnPage = function(pageCount,callExport, callQuery) {
		try{pageCount = $.cookie("PAGE_COUNT");}catch(e){};//从COOCIE读
		pageCount = (pageCount != null) ? pageCount : 10;
		var obj = this;
		//无查询数据时提示信息
		var html = "<div style='float:left;padding:5px 0;background:#fff;font-weight:bold;width:100%;margin-top:-10px;text-align:left'><span style='padding:0 10px'>无查询结果</span></div>";
		obj.clone().attr("id","_noQueryDataMsg").html(html).insertBefore(obj).hide();
		//翻页内容
		html = "<table cellSpacing='0' cellPadding='2' width='100%' border='0'>"
				+ "<tr><td nowrap align='right'><table cellSpacing='0' cellPadding='0' border='0'><tr>";
//				+ "<td nowrap id='_printSet' style='cursor:hand;font-size:9pt;padding-right:5pt;'><img alt='设置' src='/ECOMM/images/query/printall_button.gif' align='absMiddle' border='0' >设置</td>"
//				+ "<td nowrap id='_printList' style='cursor:hand;font-size:9pt;padding-right:5pt;'><img alt='打印' src='/ECOMM/images/query/print.gif' align='absMiddle' border='0' >打印</td>"
				if(callExport) {
					html += "<td nowrap id='_exportList' style='cursor:hand;font-size:9pt;padding-right:5pt;'><img alt='导出' src='/ECOMM/images/query/exportbutton.gif' align='absMiddle' border='0'>导出</td>";
				}
				html += "<td nowrap style='font-size:9pt;color:#ff0000;'><font style='color:#000000;letter-spacing:1;'>总记录数[</font><span id='_totalCount'></span><font style='color:#000000;letter-spacing:1;'>]</font>&nbsp;</td>"
				+ "<td nowrap style='font-size:9pt;color:#ff0000;'><font style='color:#000000;letter-spacing:1;'>共[</font><span id='_totalPageCount'></span><font style='color:#000000;letter-spacing:1;'>]页</font>&nbsp;</td>"
				+ "<td nowrap style='font-size:9pt;color:#ff0000;'><font style='color:#000000;letter-spacing:1;'>每页<input id='pageCount' type='text' class='Number_input'  tabindex='-1'  maxlength='3' size='3' value='" + pageCount +"' onpaste='return false' ondrop='return false' >条记录&nbsp;</td>"
				+ "<td nowrap style='cursor:hand;'><img alt='第一页' src='/ECOMM/images/query/home.jpg' align='absMiddle' border='0' id='_toFirstPage'> </td>"
				+ "<td nowrap id='_pageNoButBef' style='cursor:hand;'><img alt='前十页' src='/ECOMM/images/query/prepage.jpg' align='absMiddle' border='0' id='_toPrevious10Page'> </td>"
				
				+ "<td nowrap style='cursor:hand;font-size:9pt;background-image:url(/ECOMM/images/query/number_bg.jpg);'>&nbsp;</td>"
				+ "<td nowrap style='cursor:hand;'><img alt='后十页' src='/ECOMM/images/query/backpage.jpg' align='absMiddle' border='0' id='_toNext10Page'> </td>"
				+ "<td nowrap style='cursor:hand;'><img alt='最后一页' src='/ECOMM/images/query/end.jpg' align='absMiddle' border='0' id='_toLastPage'> </td>"
				+ "</tr></table></td></tr>"
				+ "</table>"
				+ "<input id='currentPageNo' type='hidden' value='1'/>";
		obj.html(html).hide();
//		
//		$("#_printSet", obj).click(function () {
//			alert("打印设置");
//		});
//		$("#_printList", obj).click(function () {
//			alert("打印列表");
//		});
		$("#_exportList", obj).click(function () {
			if($.isFunction(callExport)) {
				callExport();
			} else {
				exportList();
			}
		});
		
		var totalPage;//总页数
	    //跳转到第几页
		this.gotoPage = function(pageNo){
		    if(isNaN(pageNo)){
		        alert("页索引只能为数字！");
		        return;
		    } else if(pageNo < 1){
		        pageNo = 1;
		    }
		    if (totalPage && pageNo > totalPage) {
		    	pageNo = totalPage;
		    }
		    $("#currentPageNo",obj).val(pageNo);
		    if (callQuery) {
				callQuery();
			} else {
				queryList();//页面翻页查询的函数名统一为queryList();
			}
		};
		//设置翻页数据
	    this.setPageData = function(data) {
	    	if(!data || data.totalCount == 0){
	    		obj.hide();
	    		obj.prev().show();//显示无查询结果
	    		totalPage = null;
				return ;
			}
			var currentPageNo = data.currentPageNo;
			var currentPageSize = data.currentPageSize;
			var totalCount = data.totalCount;
			var totalPageCount = data.totalPageCount;
			
			$(".pageNoBut", obj).remove();//移除页码
			var startPageNo = parseInt((currentPageNo - 1) / 10) * 10 + 1;//开始显示页码
			var endPageNo = startPageNo + 9;//结束显示页码
			if (endPageNo > totalPageCount) {
					endPageNo = totalPageCount;
			}
			var pageNoButTD = "";
			for (var i = startPageNo; i <= endPageNo; i++) {
				if (i == currentPageNo) {
					pageNoButTD += "<td nowrap class='pageNoBut' style='background-image:url(/ECOMM/images/query/number_bg.jpg);'><font color='#FF0000' style='cursor:hand;font-size:9pt;'>&nbsp;" + i + "</font></td>";//当前页
				} else {
					pageNoButTD += "<td nowrap class='pageNoBut pageNoButEnable' style='cursor:hand;font-size:9pt;background-image:url(/ECOMM/images/query/number_bg.jpg);'>&nbsp;" + i + "</td>";
				}
			}
			$("#_pageNoButBef").after(pageNoButTD);
			
			$(".pageNoButEnable", obj).click(function() {//页码点击事件
				obj.gotoPage(parseInt($(this).text()));
			});
			
			 $("#pageCount", obj).unbind().change(function() {//一页显示数改变事件
			 	var _pcount = parseInt($(this).val());
			 	if(_pcount < 1 || isNaN(_pcount)) {
			 		_pcount = 10;
			 	}
			 	$(this).val(_pcount);
				obj.gotoPage(1);
				try{$.cookie("PAGE_COUNT",_pcount,{expires:120});}catch(e){};//写入COOCIE
				return false;
			}).keypress(function(e){
		   		if(e.keyCode == 13){
		  			obj.gotoPage(1);
		       		return false;
		   		}
			});
			
			var _ele = $("#_toFirstPage", obj).unbind();
			if(currentPageNo > 1) {//首页事件
				_ele.click(function() {
					obj.gotoPage(1);
				});
			}
			_ele = $("#_toPrevious10Page", obj).unbind();
			if(startPageNo > 10){//上10页事件
				_ele.click(function() {
					obj.gotoPage(startPageNo - 10);
				});
			}
			_ele = $("#_toNext10Page", obj).unbind();
			if(endPageNo < totalPageCount){//下10页事件
				_ele.click(function() {
					obj.gotoPage(startPageNo + 10);
				});
			}
			_ele = $("#_toLastPage", obj).unbind();
			if(currentPageNo < totalPageCount) {//未页事件
				_ele.click(function() {
					obj.gotoPage(totalPageCount);
				});
			}
			$("#_totalCount", obj).text(totalCount);
			$("#_totalPageCount", obj).text(totalPageCount);
			
			totalPage = totalPageCount;
			
			$("#currentPageNo",obj).val(currentPageNo);//更新当前页码，查询当页无数据时后台会自跳转到上一页
	    	obj.show();
	    	obj.prev().hide();
	    };
		//取得当前页码
	    this.getCurrentPageNo = function() {
	    	return $("#currentPageNo",obj).val();
	    };
	    //取得总页数
	    this.getPageCount = function() {
	    	return $("#pageCount",obj).val();
	    };
	    //设置当前页码
	    this.setCurrentPageNo = function(currentPageNo) {
	    	$("#currentPageNo",obj).val(currentPageNo);
	    };
	    //设置总页数
	    this.setPageCount = function(pageCount) {
	    	$("#pageCount",obj).val(pageCount);
	    };
		return this;
	}
	
	//检查AJAX返回的错误信息，
	//参数json.msg是后台返固定的格式;
	//参数msg不传时取后台的错误信息;
	//参数cmd超时时回调方法或执行的命令
	$.checkErrorMsg = function(json, msg, cmd) {
		if (json && json.msg) {
			var code = json.msg.code;
			if (code == "1") {
				return true;
			} else if (code == "-1") {
	        	alert("会话已超时,请重新登入");
	        	if (typeof cmd == "function") {
	        		cmd();
	        	} else if (cmd == "close") {
	        		window.close();
	        	} else {
	        		top.location.reload();
	        	}
	        	return false;
        	} else {
                alert((msg) ? msg : json.msg.text);
                return false;
        	}
		} else {
			alert("返回的JSON格式不正确");
			return false;
		}
	};
    
     //日期比较
    $.compareDate = function(beginDate, endDate) {
    	if (!beginDate || !endDate) {
    		return 0;
    	}
    	return Number(beginDate.replace(/(-|:| )/igm, "")) > Number(endDate.replace(/(-|:| )/igm, ""));
    };
    
    //input验证，参数input：input的Id或JQuery对像；label：input的标签名；required：是否是必需的（不能为空）；illegalChar：不能包含的字符；maxLength：长度限制（0为不限制）
    $.validInput = function(input, label, required, illegalChar, maxLength){
    	if(!input){
    		alert("验证对象为空");
			return true;
		}
		var inputObj = (typeof(input) == "string") ? $("#" + input) : input;
		var validValue = $.trim(inputObj.val());
		validValue = validValue.replace(/[　]/g, "");//将全角空格替换成空串
		if(!validValue){
			//非空验证
			if (required) {
				alert(label + "不能为空");
				inputObj.focus();
				return true;
			} else {
				return false;
			}
		}
		if (illegalChar) {
			//非法字符验证
			var re = new RegExp(".*?([" + illegalChar + "]?).*?","igm");
			var matches = validValue.match(re);
			var matchString = "";
			for(var i=0; i < matches.length; i++){
				var item = matches[i];
				matchString += item;
			}
			if(matchString){
				alert(label + "不能包含字符：" + matchString);
				inputObj.focus();
				return true;
			}
		}
		if (maxLength) {
			//长度限制
			var re = /[^\x00-\xff]/g;
			var tem = validValue.replace(re, "**");//将中文汉字替换成两个字符
			re = /[·]/g;
			tem = tem.replace(re, "**");//特殊字符替换成两个字符
			if (tem.length > maxLength) {
				alert(label + "长度不能超过" + maxLength + "（一个汉字长度为2）");
				inputObj.focus();
				return true;
			}
		}
		return false;
    };
    
    $.validNumber = function(input, label, required, maxValue){
    	if(!input){
    		alert("验证对象为空");
			return true;
		}
		var inputObj = (typeof(input) == "string") ? $("#" + input) : input;
		var validValue = $.trim(inputObj.val());
		validValue = validValue.replace(/[　]/g, "");//将全角空格替换成空串
		if(!validValue){
			//非空验证
			if (required) {
				alert(label + "不能为空");
				inputObj.focus();
				return true;
			} else {
				return false;
			}
		}
		var re = new RegExp("^([-]){0,1}([0-9]){1,}([.]){0,1}([0-9]){0,}$","igm");
		if(!re.test(validValue)){
       		alert(label+"不是有效的数字类型");
       		inputObj.focus();
       		return true;
       	}
       	if (maxValue) {
			//最大值
			
			if (Number(validValue) > maxValue) {
				alert(label + "不能大于" + maxValue);
				inputObj.focus();
				return true;
			}
		}
       	return false;
    }
    
    $.validEmail=function (input, label, required){
    	if(!input){
    		alert("验证对象为空");
			return true;
		}
		var inputObj = (typeof(input) == "string") ? $("#" + input) : input;
		var validValue = $.trim(inputObj.val());
		validValue = validValue.replace(/[　]/g, "");//将全角空格替换成空串
		if(!validValue){
			//非空验证
			if (required) {
				alert(label + "不能为空");
				inputObj.focus();
				return true;
			} else {
				return false;
			}
		}
        var reg = new RegExp("^[0-9a-zA-Z]+@[0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$");
        if( !reg.test(validValue)){
        	alert(label+"不是有效的Email格式");
        	inputObj.focus();
        	return true;
		}
      	return false;
    }
    
    $.validTel=function (input, label, required){
    	if(!input){
    		alert("验证对象为空");
			return true;
		}
		var inputObj = (typeof(input) == "string") ? $("#" + input) : input;
		var validValue = $.trim(inputObj.val());
		validValue = validValue.replace(/[　]/g, "");//将全角空格替换成空串
		if(!validValue){
			//非空验证
			if (required) {
				alert(label + "不能为空");
				inputObj.focus();
				return true;
			} else {
				return false;
			}
		}
       	var reg = /^\d{3,4}-\d{7,9}(-\d{1,4})?$/;
       	if(!reg.test(validValue)){
       		alert("您输入的" + label + "格式有误，请按照\"xxx-xxxxxxxx-xxxx\"的格式重新输入");
       		inputObj.focus();
       		return true;
       	}
       	return false;
    }
    
    //验证汉字
    $.validChinese=function (input, label, required){
    	if(!input){
    		alert("验证对象为空");
			return true;
		}
		var inputObj = (typeof(input) == "string") ? $("#" + input) : input;
		var validValue = $.trim(inputObj.val());
		validValue = validValue.replace(/[　]/g, "");//将全角空格替换成空串
		if(!validValue){
			//非空验证
			if (required) {
				alert(label + "不能为空");
				inputObj.focus();
				return true;
			} else {
				return false;
			}
		}
       	var reg = /([\u4E00-\u9FA5]|[\uFE30-\uFFA0])/g;//汉字
       	//var reg = /[^\x00-\xff]/g;//汉字
       	if(reg.test(validValue)){
       		alert(label+"不能为汉字");
       		inputObj.focus();
       		return true;
       	}
       	return false;
    }
    
    //验证邮政编码：按我国邮政编码的编码规则：采用六位阿拉伯数字组成
    $.validZipCode=function (input, label, required){
    	if(!input){
    		alert("验证对象为空");
			return true;
		}
		var inputObj = (typeof(input) == "string") ? $("#" + input) : input;
		var validValue = $.trim(inputObj.val());
		validValue = validValue.replace(/[　]/g, "");//将全角空格替换成空串
		if(!validValue){
			//非空验证
			if (required) {
				alert(label + "不能为空");
				inputObj.focus();
				return true;
			} else {
				return false;
			}
		}
       	var reg = /^[0-9]{6}$/;
       	if(!reg.test(validValue)){
       		alert(label+"不是有效的格式");
       		inputObj.focus();
       		return true;
       	}
       	return false;
    }
    //权限点枚举
	$.BIConstants = {
        ASSIGN:"assign",//授权
        MOVE:"move"//移动
    };
    
	//Javascript对象转JSON
	$.toJSON = function (o){
		var r = [];
	    if(typeof o =="string") return "\""+o.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";
	    if(typeof o == "object"){
	        if(!o.sort){
	            for(var i in o)
	                r.push(i+":"+$.toJSON(o[i]));
	            if(!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)){
	                r.push("toString:"+o.toString.toString());
	            }
	            r="{"+r.join()+"}"
	        }else{
	            for(var i =0;i<o.length;i++)
	                r.push($.toJSON(o[i]))
	            r="["+r.join()+"]"
	        }
	        return r;
	    }
	    return o.toString();
	};
	
	/**
	* 时间对象的格式化;
	*/
	$.formatDate = function (date, format){
	 /*
	  * eg:format="yyyy-MM-dd hh:mm:ss";
	  */
	 	var o = {
	  		"M+" :  date.getMonth()+1,  //month
			"d+" :  date.getDate(),     //day
			"h+" :  date.getHours(),    //hour
			"m+" :  date.getMinutes(),  //minute
			"s+" :  date.getSeconds(), //second
			"q+" :  Math.floor((date.getMonth()+3)/3),  //quarter
			"S"  :  date.getMilliseconds() //millisecond
		}
		if(/(y+)/.test(format)) {
	    	format = format.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
		}
		for(var k in o) {
	    	if(new RegExp("("+ k +")").test(format)) {
	      		format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
	    	}
	   	}
	 	return format;
	};
	
})(jQuery);